{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "step1: 对输入的I/O数据进行处理，I/O数据看作是nlp里面的文本数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import scipy.io as sio\n",
    "import numpy as np\n",
    "from shutil import copyfile"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "path = \"./Data_Set\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "files = os.listdir(path)\n",
    "data = []\n",
    "labels = []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "def del_file(filepath):\n",
    "    \"\"\"\n",
    "    删除某一目录下的所有文件或文件夹\n",
    "    :param filepath: 路径\n",
    "    :return:\n",
    "    \"\"\"\n",
    "    import shutil\n",
    "    del_list = os.listdir(filepath)\n",
    "    for f in del_list:\n",
    "        file_path = os.path.join(filepath, f)\n",
    "        if os.path.isfile(file_path):\n",
    "            os.remove(file_path)\n",
    "        elif os.path.isdir(file_path):\n",
    "            shutil.rmtree(file_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "del_file(\"./DATA_RESIZE\")\n",
    "for file in files:\n",
    "        if file.startswith(\"A\"):\n",
    "            device = file.split('_')[2]\n",
    "            y = int(device) - 1\n",
    "            round = int(file.split('_')[4][0])\n",
    "            data = sio.loadmat(os.path.join(path, file))\n",
    "            X = data[\"Brush_Data_Temp\"]\n",
    "            X = X[0:1600]\n",
    "            real = X.real\n",
    "            imag = X.imag\n",
    "            \n",
    "            real = real.transpose()\n",
    "            imag = imag.transpose()\n",
    "            real = real[0]\n",
    "            imag = imag[0]\n",
    "                   \n",
    "            \n",
    "            result = real[0:160]\n",
    "            im = imag[0:160]\n",
    "            result = np.vstack((result, im))\n",
    "            \n",
    "            k = 1\n",
    "            while k < 10:\n",
    "                r = real[160*k: 160*(k + 1)]\n",
    "                result = np.vstack((result, r))\n",
    "                i = imag[160*k: 160*(k + 1)]\n",
    "                result = np.vstack((result, i))\n",
    "                k += 1\n",
    "            \n",
    "            name =\"NO_\"+str(\"A_\"+device)+\"_\"+str(round) +\".npy\"\n",
    "            path1 = \"./DATA_RESIZE/\" + name\n",
    "            np.save(path1, result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(20, 160)"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result.shape"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
